package org.example.service.impl;

import org.example.dao.CourseDao;
import org.example.dao.CurriculumPlanDao;
import org.example.dao.PlanDao;
import org.example.dto.ClassDto;
import org.example.dto.ClassroomDto;
import org.example.dto.CurriculumPlanDto;
import org.example.dto.GiveInstructionDto;
import org.example.pojo.Classes;
import org.example.pojo.Classroom;
import org.example.pojo.Course;
import org.example.pojo.Plan;
import org.example.service.CurriculumPlanService;
import org.example.vo.ClassVo;
import org.example.vo.CurriculumPlanVo;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class CurriculumPlanServiceImpl implements CurriculumPlanService {
    @Resource
    private PlanDao dao;
    @Resource
    private CourseDao course;

    private CurriculumPlanDto PoTransToDto(Plan plan){
        System.out.println(plan.toString());
        CurriculumPlanDto curriculumPlanDto=new CurriculumPlanDto();
        curriculumPlanDto.setSemester(String.valueOf(plan.getSemester()));
        curriculumPlanDto.setDepartment(plan.getDepartname());
        curriculumPlanDto.setMajor(plan.getMajorname());
        curriculumPlanDto.setId(plan.getPlanno());
        curriculumPlanDto.setCurriculumPlanName(plan.getPlanname());
        curriculumPlanDto.setCurriculumId(String.valueOf(plan.getCourses(0)));
        curriculumPlanDto.setCurriculumName("英语");
        curriculumPlanDto.setSchoolYear("19");
        return curriculumPlanDto;
    }
    private Plan VoTransToPo(CurriculumPlanVo curriculumPlanVo){
        Plan plan=new Plan();
        plan.setPlanno(curriculumPlanVo.getId());
        plan.setPlanname(curriculumPlanVo.getCurriculumName());
        plan.setMajorname(curriculumPlanVo.getMajor());
//        plan.setMajorno();
        plan.setDepartname(curriculumPlanVo.getDepartment());
        plan.setSemester(Integer.valueOf(curriculumPlanVo.getSemester()));

        return plan;
    }

    @Override
    public List<CurriculumPlanDto> queryAllCurriculumPlan() {
        List<Plan> planList=dao.queryAll();
        List<CurriculumPlanDto> curriculumPlanDtoList=new ArrayList<>();
        for(int i=0;i<planList.size();i++)
            curriculumPlanDtoList.add(i,PoTransToDto(planList.get(i)));
        return curriculumPlanDtoList;
    }

    @Override
    public Integer addCurriculumPlan(CurriculumPlanVo curriculumPlan) {

        System.out.println("==================================dao" + dao);
        if(dao.insert(VoTransToPo(curriculumPlan)))
            return 1;
        else
            return 0;
    }

    @Override
    public Integer deleteCurriculumPlan(int id) {
        if(dao.delete(id))
            return 1;
        else
            return 0;
    }

    @Override
    public Integer updateCurriculumPlan(CurriculumPlanVo curriculumPlan) {
        if(dao.update(VoTransToPo(curriculumPlan)))
            return 1;
        else
            return 0;
    }

    @Override
    public Integer queryCurriculumPlanIdByName(String curriculumPlanName) {
        return 1;
    }

    @Override
    public CurriculumPlanDto queryCurriculumPlanNameById(Integer id) {
        Plan plan=new Plan();
        plan.setPlanno(id);
        return PoTransToDto(dao.queryByCondition(plan).get(0));
    }

    @Override
    public Integer count() {
        return dao.queryAll().size();
    }

    @Override
    public Integer countCurriculumPlanBySchoolYearAndSemester(String schoolYear, String semester) {

        return 1;
    }

    @Override
    public List<GiveInstructionDto> queryAllGiveInstruction() {
        List<GiveInstructionDto> giveInstructionDtoList=new ArrayList<>();
        GiveInstructionDto giveInstructionDto=new GiveInstructionDto();
        giveInstructionDto.setCurriculumId(0);
        giveInstructionDto.setCurriculumName("英语");
        giveInstructionDto.setTeacherName("吴荣昌");
        return giveInstructionDtoList;
    }

    @Override
    public List<GiveInstructionDto> queryCurriculumByName(String curriculumName) {
        List<GiveInstructionDto> giveInstructionDtoList=new ArrayList<>();
        GiveInstructionDto giveInstructionDto=new GiveInstructionDto();
        giveInstructionDto.setCurriculumId(0);
        giveInstructionDto.setCurriculumName("英语");
        giveInstructionDto.setTeacherName("吴荣昌");
        return giveInstructionDtoList;
    }

    @Override
    public Integer countCurriculum() {
        return course.queryAll().size();
    }

    @Override
    public GiveInstructionDto queryCurriculumById(Integer curriculumId) {
        GiveInstructionDto giveInstructionDto=new GiveInstructionDto();
        giveInstructionDto.setCurriculumId(0);
        giveInstructionDto.setCurriculumName("英语");
        giveInstructionDto.setTeacherName("吴荣昌");
        return giveInstructionDto;
    }
}
